<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<!--反馈编辑模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-edit-ret-sta">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">反馈编辑</h4>
            </div>
            <div class="modal-body">
                <form id="editRetForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="prpdRetSta" class="col-sm-2 control-label no-padding-right">反馈编辑状态：</label>
                        <div class="col-sm-10">
                            <input name="prpdId" type="hidden" style="display: none"/>
                            <select id="prpdRetSta" name="prpdRetSta" class="form-control" style="width: 200px;">
                                <option value="">请选择</option>
                                <option value="1">未执行</option>
                                <option value="2">执行中</option>
                                <option value="3">已完成</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" shiro:hasPermission="pro:productPlan:feedback" id="btn_save_edit_ret">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>生产计划编辑与反馈</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header" style="padding-left: 25px;">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="prodNo" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="proName" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        部门/车间
                                    </label>
                                    <label class="control-label">
                                        <input name="dep" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入部门/车间"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        是否重点
                                    </label>
                                    <label class="control-label">
                                        <select name="isKey" class="form-control">
                                            <option value="" selected="selected">全部</option>
                                            <option value="1">重点</option>
                                            <option value="0">非重点</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        类别
                                    </label>
                                    <label class="control-label">
                                        <select name="typ" class="form-control">
                                            <option value="" selected="selected">全部</option>
                                            <option value="1">设备类</option>
                                            <option value="2">其他类</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        反馈编辑状态
                                    </label>
                                    <label class="control-label">
                                        <select name="retSta" class="form-control">
                                            <option value="" selected="selected">全部</option>
                                            <option value="1">未执行</option>
                                            <option value="2">执行中</option>
                                            <option value="3">已完成</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">交货时间：</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime"
                                               readonly="readonly"/></label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar" class="row">
                    <a href="/task/facPlaEdiAndRet/add" shiro:hasPermission="pro:productPlan:edit" target="view_window" class="btn btn-info">添加</a>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table, tempTable, tempData = new Array(), currentProject;
    $(function () {
        /**
         * 加载列表
         */
        loadTable();
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
        /**
         * 保存反馈编辑状态
         */
        $("#btn_save_edit_ret").click(function () {
            js.validSubmit({
                formId: "editRetForm",
                url: ctx + "task/facPlaEdiAndRet/saveEditRetSta",
                data: new FormData($("#editRetForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-edit-ret-sta");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /**
         * 验证
         */
        js.validate.init("editRetForm", {
            fields: {
                prpdRetSta: {validators: {notEmpty: {message: '尊敬的用户，请选择反馈编辑状态！'}}},
            }
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-edit-ret-sta", function () {
            js.validate.reset("editRetForm");
            js.reset("editRetForm");
        });
    });

    /**
     * 重新加载
     */
    function reloadTable() {
        js.table.refresh(table);
    }

    /**
     * 加载列表
     */
    function loadTable() {
        table = js.table.init({
            url: ctx + "task/facPlaEdiAndRet/list",
            showColumns: true,
            showExport: true,
            columns: [
                // {
                //     checkbox: true,
                //     width: '30px',
                //     formatter: function (value, row, index) {
                //         // 正常提报并且数据正常状态可以提交选择
                //         if ((row.proStatus === 1 || row.proStatus === 4) && row.propIsSch === 1) {
                //             return {disabled: false}
                //         } else {
                //             return {disabled: true}
                //         }
                //     }
                // },
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '项目编号', field: 'prodNo',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'proName',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目数量', field: 'proNum',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '交货时间', field: 'delDat'
                },
                {
                    title: '是否重点', field: "isKey",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (parseInt(value) === 1) {
                                return '是';
                            } else {
                                return '否';
                            }
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '类别', field: "typ",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (value === 1) {
                                return '设备类';
                            } else if (value === 2) {
                                return '其他类';
                            }
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '部门/车间', field: "dep",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '工作任务', field: "plaNam",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '计划开始时间', field: "staDat",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '计划完成时间', field: "endDat",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '备注', field: "rem",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '反馈编辑状态', field: "retSta",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (value === 1) {
                                return '<label class="badge label-default">未执行</label>';
                            } else if (value === 2) {
                                return '<label class="badge label-warning">执行中</label>';
                            } else if (value === 3) {
                                return '<label class="badge label-success">已完成</label>';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '160',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (row.typ === 2 && hasP('pro:productPlan:feedback')) {
                            elements.push('<button class="btn btn-warning btn-xs" onclick="editRetSta(' + row.id + ',' + row.retSta + ',' + row.typ + ')">反馈编辑</button>');
                        }
                        if (row.retSta === 1 && hasP('pro:productPlan:del')) {
                            elements.push('<button class="btn btn-danger btn-xs" onclick="remove(' + row.id + ',' + row.typ + ')">删除</button>');
                        }
                        return elements.join('');
                    }
                }
            ]
        });
    }

    /**
     * 删除
     */
    function remove(id, typ) {
        //设备类
        if (typ === 1) {
            js.confirmPost({
                content: "尊敬的用户，您确认要删除此生产计划吗？",
                url: ctx + "task/facPlaEdiAndRet/removeDevicesClass",
                data: {
                    id:id
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                }
            });
        }
        //其他类
        else if (typ === 2) {
            js.confirmPost({
                content: "尊敬的用户，您确认要删除此生产计划吗？",
                url: ctx + "task/facPlaEdiAndRet/removeOtherClass",
                data: {
                    id:id
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                }
            });
        }
    }

    /**
     * 重新加载
     */
    function reLoad() {
        js.table.refresh(table);
    }

    /**
     * 反馈状态编辑
     * @param id
     */
    function editRetSta(id, retSta, typ) {
        if (typ === 2) {
            $("#editRetForm [name='prpdId']").val(id);
            $("#editRetForm [name='prpdRetSta']").val(retSta);
            js.modal.open('modal-edit-ret-sta');
        }
    }
</script>
</body>
</html>